package com.yenlien.traceyun.control.controller;

import com.yenlien.traceyun.control.dao.GoodsLevelDao;
import com.yenlien.traceyun.control.entity.GoodsLevel;
import com.yenlien.traceyun.control.interceptor.UserAuthUtil;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jialong
 * @date 2021/05/20
 * @description: 货物品级定义
 **/

@RestController
@RequestMapping("/goodsLevel")
public class GoodsLevelController extends BaseController {

//    @Autowired
//    private GoodsLevelService goodsLevelService;

    @Autowired
    private GoodsLevelDao goodsLevelDao;


    @PostMapping(value = "/save")
    public Object save(@Validated @RequestBody List<GoodsLevel> goodsLevels) {
        String companyId = UserAuthUtil.getLoginUser().getCompanyId();
        for (GoodsLevel goodsLevel : goodsLevels) {
            goodsLevel.setCompanyId(companyId);
        }
        return success(goodsLevelDao.saveAll(goodsLevels));
    }

    @GetMapping(value = "/findList")
    public Object findByList() {
        return success(goodsLevelDao.findByCompanyId(UserAuthUtil.getLoginUser().getCompanyId()));
    }

    @GetMapping(value = "/findById/{id}")
    public Object findById(@PathVariable Long id) {
        return success(goodsLevelDao.findById(id));
    }


}
